<template>
  <div>
    <el-tree
      ref="tree"
      :default-expanded-keys="expandedkeys"
      :highlight-current="true"
      lazy
      :load="loadNode"
      node-key="id"
      :props="props"
    >
      <template #default="{ node, data }">
        <slot :data="data" :node="node">{{ node.label }}({{ data.sum }})</slot>
      </template>
      <!-- <slot></slot> -->
    </el-tree>
  </div>
</template>

<script>
  export default {
    name: 'Pcstree',
    props: {
      pcsid: {
        type: Object,
        default: () => {
          return {}
        },
      },
      expandedkeys: {
        type: Array,
        default: () => {
          return []
        },
      },
      searchdata: {
        type: Array,
        default: () => {
          return []
        },
      },
    },
    data() {
      return {
        props: {
          label: 'pcs',
          children: 'pcschildren',
        },

        treedata: [],
      }
    },

    created() {},
    mounted() {},
    methods: {
      async loadNode(node, resolve) {
        let r = []

        if (node.level == 0) {
          r = await this.$store.dispatch('station/getstationone')
        } else if (
          this.searchdata.find((e) => {
            return e.pid == node.data.id
          })
        ) {
          r = this.searchdata.filter((e) => {
            return e.pid == node.data.id
          })
        } else {
          r = await this.$store.dispatch('station/getstationpid', node.data.id)
        }
        return resolve(r)
      },
      getCurrentNode() {
        return this.$refs.tree.getCurrentNode()
      },
      setCurrentKey() {},
    },
  }
</script>
<style>
  .el-tree-node__content {
    height: 50px;
  }
</style>
